package com.x.api;

import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * ClassName: ApiController
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.09.11 22:18
 */

@Controller
@RequestMapping("api")
@ResponseBody
public class ApiController {
    @Autowired
    private ServletContext servletContext;

    @RequestMapping("apiTest")
    public void test(HttpServletResponse response,
                     HttpServletRequest request,
                     HttpSession session){
        /**
         * 使用原生对象就可以
         *      ServletContext  [1.最大的配置文件 2.全局最大共享域  3.核心api getRealPath]
         *      方案1: request获取 session获取
         *      方案2： ServletContext 会自动装入到ioc容器 直接全局注入就可以(@Autowired)
         */
        ServletContext servletContext1 = request.getServletContext();
        ServletContext servletContext2 = session.getServletContext();

        System.out.println(servletContext==servletContext1);//true
        System.out.println(servletContext==servletContext2);//true

    }
}
